package com.joysuch.wwyt.quartz.createtable;

import com.joysuch.wwyt.quartz.createtable.constant.TableNamePrefixConstant;
import com.joysuch.wwyt.quartz.createtable.handler.CreateTableHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

/**
 * 隐患排查动态创建表
 *
 * @author 叶君翔
 * @date 2023/07/11 10:35
 */
@Slf4j
@Component
public class InvestigateCreateTableSchedule {

    @Resource
    private CreateTableHandler createTableHandler;

    /**
     * 每年1月1日0点10分、40分(兜底)各执行一次, 生成上一年的表
     */
    @Scheduled(cron = "0 10/30 0 1 1 ?")
    public void createTableTask() {
        int nowYear = LocalDate.now().getYear();
        int year = nowYear - 1;
        Map<String, String> map = new HashMap<>();
        map.put(TableNamePrefixConstant.INVESTIGATE_TASK, TableNamePrefixConstant.INVESTIGATE_TASK + "_" + year);
        map.put(TableNamePrefixConstant.INVESTIGATE_TASK_ASSIGN, TableNamePrefixConstant.INVESTIGATE_TASK_ASSIGN + "_" + year);
        map.put(TableNamePrefixConstant.INVESTIGATE_TASK_SUMMARY, TableNamePrefixConstant.INVESTIGATE_TASK_SUMMARY + "_" + year);
        map.put(TableNamePrefixConstant.INVESTIGATE_RECORD, TableNamePrefixConstant.INVESTIGATE_RECORD + "_" + year);
        map.put(TableNamePrefixConstant.INVESTIGATE_RECORD_ITEM, TableNamePrefixConstant.INVESTIGATE_RECORD_ITEM + "_" + year);
        createTableHandler.createTable(map);
    }

}
